var removeDuplicates = function (nums) {
  for (let i = 2; i < nums.length; i++) {
    if (nums[i - 2] === nums[i]) {
      nums.splice(i, 1);
      i--;
    }
  }
  return nums.length;
}

// 1 1 1 2 2 3 变为 1 1 2 2 3
var removeDuplicates = function (nums) {
  let n = nums.length;
  if (n < 3) return n;
  let j = 1;
  for (let i = 2; i < n; i++) {
    if (nums[i] !== nums[j - 1]) {
      j++;
      nums[j] = nums[i];
    }
  }
  return j + 1;
}